function generateSideBar(){
    getSideBarRemote();
}

function getSideBarRemote(){
    $.ajax({
        url:"menu/get/whole/tree.json",
        async:"false",
        type:"post",
        dataType:"json",
        success:function (responseData) {
            if(responseData.result == "SUCCESS"){
               console.log(responseData.data)
                // 遍历一级目录
                // 拿到的menu的root目录，我们访问他的children就是一级目录了
                var childrenArray = responseData.data.children;
               for (var i=0;i<childrenArray.length;i++) {
                   var children = childrenArray[i];
                   //console.log("children:"+children.name)

                   var id = "leftTree_"+children.id;
                   // 控制面板是一个超链接，除了他，全部用span显示
                   if(children.id == 2){
                       var li ="<li class='list-group-item tree-closed' >"
                           + "<a href='"+children.url+"'>"
                           +"<i class='"+children.icon+"'></i> "
                           +children.name
                           +"</a>"
                   }else{
                       var li ="<li class='list-group-item tree-closed' >"
                           + "<span id='"+id+"'>"
                           +"<i class='"+children.icon+"'></i> "
                           +children.name
                           +"</span><div></div>"
                   }

                   $("#leftTree").append(li);
               }

                // jq子类选择器，属性选择器的正确写法，不要留空格
                // $("li.list-group-item>span"),找到一级菜单，也就是我们刚刚拼接的一级菜单（第一次遍历）
                // 把一级菜单遍历出来之后，对照pid拼接二级菜单
                $("li.list-group-item>span").each(function () {
                    console.log(this.id);
                    console.log(childrenArray);
                    for (var j=0;j<childrenArray.length;j++) {
                        // childrenArray是一级菜单，如果我们想访问二级菜单，需要childrenArray[j].children
                        var inchildrenArray = childrenArray[j].children;
                        // 遍历二级菜单
                        for(var k=0;k<inchildrenArray.length;k++){
                            var children = inchildrenArray[k];
                            // 取出他们的pid
                            var pid = "leftTree_"+children.pid;
                            var parentId = this.id;
                            // pid与一级菜单的id比较，如果一样，开始拼接二级菜单
                            if(parentId == pid){
                                var li = "<li style='height:30px;'>"
                                        +"<a href='"+children.url+"'>"
                                        +"<i class='"+children.icon+"'></i> "
                                        +children.name
                                        +"</li>"
                                var ul = "<ul style='margin-top:10px;display:none;'>"+li+"</ul>";
                                $(this).next().append(ul)
                            }
                        }


                    }

                })




            }

            if(responseData.result == "FAILED"){
                layer.msg(responseData.message);
            }
        },
        error:function () {
            layer.msg("请求出错！");
        }
    })
}